<!-- 17 -->
<script lang='ts' setup>
//@ts-nocheck
// 关闭ts检查
// @ts-nocheck
import { ref, computed, nextTick, onMounted } from 'vue'
import { NInput } from 'naive-ui'
import { useRoute, useRouter } from 'vue-router'
import { getDetailEx, changeState } from '@/api/request'
import { useGlobalStore } from "../../../store/GlobalStore";
const route = useRoute()
// 试卷头的基本信息
// 使用onMounted生命周期函数
const jwtToken = localStorage.getItem('jwtToken')

onMounted(() => {
	// name.value = localStorage.getItem('name')
	// sno.value = localStorage.getItem('snoId')
	// sClass.value = localStorage.getItem('className')
	// expName.value = localStorage.getItem('expName')
	// 获取保存的信息
	getDetailEx(jwtToken, eid, rid).then((res) => {
		console.log(res.data.data[0], 'socket数据')
		model.value.forEach((element) => {
			var obj = element
			var kid = obj.kid
			if (res.data.data[0].hasOwnProperty(kid)) {
				obj.value = res.data.data[0][kid]
				obj.timeStamp = res.data.data[0]['t' + kid]
			}
		})
		console.log('处理后', model.value)
	})
})
const store=useGlobalStore()
const cid = route.query.cid
const sid = route.query.sid
const rid = route.query.rid
const eid = route.query.eid
const name = route.query.name
const classnum=route.query.classNum
const college=route.query.college
const grade=route.query.grade
const major=route.query.major
// 处理数据
// model.value = model.value.map((item) => ({
// 		role:"student",
// 		sourceId: sid,
// 		rid: rid.value,
// 		destId: tid.value,
// 		eid:"3",
// 		kid: item.kid,
// 		// 返回这个对象中第一个属性的value值
// 		value: item.value,
// 		timeStamp: item.timeStamp,
// 	}))
const tid=store.userInfo.tid
const ws = new WebSocket(`ws://210.44.37.172:8082/message?id=${tid}&role=teacher`)
ws.onopen = function (e) {
	console.log('连接成功')
	// ws.send(
	// 	// '{"rid":"2002","tid":"3000","kid":"3000","value":"3.33","timeStamp":"3.2.3"}'
	// 	'{"role":"student","sourceId":"sid","eid":"","rid":"2002","destId":"tid","kid":"3000","value":"3.33","timeStamp":"3.2.3"}'
	// )
}
ws.onmessage = function (e) {
	console.log(e.data, '接收返回的消息')
	console.log(JSON.parse(e.data), '解析一下的数据')
	if (JSON.parse(e.data).rid == rid) {
		model.value.forEach((element) => {
			if (element.kid == JSON.parse(e.data).kid) {
				element.value = JSON.parse(e.data).value
				element.timeStamp = JSON.parse(e.data).timeStamp
			}
		})
	}
}
ws.onclose = function () {
	console.log('连接关闭')
}
ws.onerror = function () {
	console.log('连接出错')
}
const checked = ref(new Array(47).fill(true))
// 复选框状态发生改变
const getState = function () {
	console.log(checked.value)
}
// 实验通过
const exOk = () => {
	changeState(jwtToken, rid, 3).then((res) => {
		console.log(res)
		console.log("rid",rid);
		
		ElMessage.success('已通过')
	})
}
const exFix = () => {
	changeState(jwtToken, rid, 1).then((res) => {
		console.log(res)
		ElMessage.success('反馈成功')
	})
}
const model = ref([
    { kid: 'k0', value: '', timeStamp: '' },
    { kid: 'k1', value: '', timeStamp: '' },
    { kid: 'k2', value: '', timeStamp: '' },
    { kid: 'k3', value: '', timeStamp: '' },
    { kid: 'k4', value: '', timeStamp: '' },
    { kid: 'k5', value: '', timeStamp: '' },
    { kid: 'k6', value: '', timeStamp: '' },
    { kid: 'k7', value: '', timeStamp: '' },
    { kid: 'k8', value: '', timeStamp: '' },
    { kid: 'k9', value: '', timeStamp: '' },
    { kid: 'k10', value: '', timeStamp: '' },
    { kid: 'k11', value: '', timeStamp: '' },
    { kid: 'k12', value: '', timeStamp: '' },
    { kid: 'k13', value: '', timeStamp: '' },
    { kid: 'k14', value: '', timeStamp: '' },
    { kid: 'k15', value: '', timeStamp: '' },
    { kid: 'k16', value: '', timeStamp: '' },
    { kid: 'k17', value: '', timeStamp: '' },
    { kid: 'k18', value: '', timeStamp: '' },
    { kid: 'k19', value: '', timeStamp: '' },
])


</script>
<template>
    <div class="paper-wrap">
        <n-card>
            <!-- 学生信息 -->
            <div class="paper-title">
                <h2>麦克尔逊干涉仪的调节与使用</h2>
                <div class="stu-info">
					<div class="stu-info-item">
						<span>学号：</span>
						<span>{{ sid }}</span>
					</div>
					<div class="stu-info-item">
						<span>姓名：</span>
						<span>{{ name }}</span>
					</div>
					<div class="stu-info-item">
						<span>班级：</span>
						<span>{{ college }}学院 {{ major }}专业 {{ grade }}级 {{ classnum }} 班</span>
					</div>
				</div>
            </div>
            <!-- 实验的基本信息 -->
            <n-divider title-placement="left">
                <h2>一、实验目的</h2>
            </n-divider>
            <div class="paper-purpose">
                <ol>
                    <li>
                        <span style="font-size: 16px">{{ model[0].value }}</span>&emsp;<span style="font-size: 12px">{{ model[0].timeStamp }}</span>
                    </li>
                    <li> <span style="font-size: 16px">{{ model[1].value }}</span>&emsp;<span style="font-size: 12px">{{ model[1].timeStamp }}</span></li>
                </ol>
            </div>
            <n-divider title-placement="left">
                <h2>二、实验仪器</h2>
            </n-divider>
            <div class="paper-instrument">
                <span style="font-size: 16px">{{ model[2].value }}</span>&emsp;<span style="font-size: 12px">{{ model[2].timeStamp }}</span>
            </div>
            <n-divider title-placement="left">
                <h2>三、实验原理</h2>
            </n-divider>
            <div class="paper-principle">
                <p class="principles"> 写出实验基本原理级公式，并画出原理图 </p>
            </div>

            <n-divider title-placement="left">
                <h2>四、数据记录与处理</h2>
            </n-divider>
            <h3>（一）基本量测量</h3>
            <div class="paper-data">
                <!-- 第一个表单 -->
                <h3> 牛顿环测量透镜的曲率半径</h3>
                <table border="1" cellpadding="2" style="
						width: 100%;
						border-collapse: collapse;
						border: 2px solid #000;
					" class="ntable">
                    <thead>
                        <tr>
                            <th>测量次数</th>
                            <th>干涉圆环编号</th>
                            <th>d<sub>m</sub>/mm</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="w-50 m-2">1</td>
                            <td class="w-50 m-2">0</td>
                            <td><span style="font-size: 16px">{{ model[3].value }}</span>&emsp;<span style="font-size: 12px">{{ model[3].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">2</td>
                            <td class="w-50 m-2">30</td>
                            <td><span style="font-size: 16px">{{ model[4].value }}</span>&emsp;<span style="font-size: 12px">{{ model[4].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">3</td>
                            <td class="w-50 m-2">60</td>
                            <td><span style="font-size: 16px">{{ model[5].value }}</span>&emsp;<span style="font-size: 12px">{{ model[5].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">4</td> 
                            <td class="w-50 m-2">90</td>
                            <td><span style="font-size: 16px">{{ model[6].value }}</span>&emsp;<span style="font-size: 12px">{{ model[6].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">5</td>
                            <td class="w-50 m-2">120</td>
                            <td><span style="font-size: 16px">{{ model[7].value }}</span>&emsp;<span style="font-size: 12px">{{ model[7].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">6</td>
                            <td class="w-50 m-2">150</td>
                            <td><span style="font-size: 16px">{{ model[8].value }}</span>&emsp;<span style="font-size: 12px">{{ model[8].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">7</td>
                            <td class="w-50 m-2">180</td>
                            <td><span style="font-size: 16px">{{ model[9].value }}</span>&emsp;<span style="font-size: 12px">{{ model[9].timeStamp }}</span></td>
                        </tr>
                        <tr>
                            <td class="w-50 m-2">8</td>
                            <td class="w-50 m-2">210</td>
                            <td><span style="font-size: 16px">{{ model[10].value }}</span>&emsp;<span style="font-size: 12px">{{ model[10].timeStamp }}</span></td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <!-- 第二个表单 -->
            <h3>(二)用线性回归法处理实验数据</h3>
            <table border="1" cellpadding="2" style="
						width: 100%;
						border-collapse: collapse;
						border: 2px solid #000;
					" class="ntable">
                <thead>
                    <tr>
                        <th colspan="2">按方程y=bx+a做线性回归分析</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>截距 a/nm</td>
                        <td><span style="font-size: 16px">{{ model[11].value }}</span>&emsp;<span style="font-size: 12px">{{ model[11].timeStamp }}</span></td>
                    </tr>
                    <tr>
                        <td>回归系数 b/nm</td>
                        <td><span style="font-size: 16px">{{ model[12].value }}</span>&emsp;<span style="font-size: 12px">{{ model[12].timeStamp }}</span></td>
                    </tr>
                    <tr>
                        <td>激光波长 λ=2|b|/nm</td>
                        <td><span style="font-size: 16px">{{ model[13].value }}</span>&emsp;<span style="font-size: 12px">{{ model[13].timeStamp }}</span></td>
                    </tr>
                </tbody>
            </table>
            <div>如果激光波长的真值为λ<sub>0</sub>=632.8mm,计算实验结果的绝对误差和相对误差。</div>
            <div>绝对误差δ=|λ-λ<sub>0</sub>|= <span class="f2"><span style="font-size: 16px">{{ model[14].value }}</span>&emsp;<span style="font-size: 12px">{{ model[14].timeStamp }}</span></span>nm,相对误差E<sub>r</sub>×100%=
                <span class="f2"><span style="font-size: 16px">{{ model[15].value }}</span>&emsp;<span style="font-size: 12px">{{ model[15].timeStamp }}</span></span>%</div>
            <n-divider title-placement="left">
                <h2>五、实验分析</h2>
            </n-divider>
            <div class="paper-analyze">
                <div style="margin-bottom: 10px; font-size: 17px">1.迈克尔干涉仪的测量精度是<span class="f2"><span style="font-size: 16px">{{ model[16].value }}</span>&emsp;<span style="font-size: 12px">{{ model[16].timeStamp }}</span></span>mm</div>
                <div style="margin-bottom: 10px; font-size: 17px">2.如果本次实验的数据的差距相对较大，主要原因可能是</div>
                <span style="font-size: 16px">{{ model[17].value }}</span>&emsp;<span style="font-size: 12px">{{ model[17].timeStamp }}</span>
                    <div style="margin-bottom: 10px; font-size: 17px">3.调节微调手轮时，没看到圆环冒出或缩进，为什么？</div>
                <span style="font-size: 16px">{{ model[18].value }}</span>&emsp;<span style="font-size: 12px">{{ model[18].timeStamp }}</span>
                    <div style="margin-bottom: 10px; font-size: 17px">4.越靠近等倾干涉圆环中心，条纹级次越
                        <span class="f2"><span style="font-size: 16px">{{ model[19].value }}</span>&emsp;<span style="font-size: 12px">{{ model[19].timeStamp }}</span></span>(填“高”或“低”)</div>
            </div>
            <div class="btn-group">
                <el-button type="primary" @click="exOk()">通过</el-button>
				<el-button type="success" @click="exFix()">需要修改</el-button>
            </div>
        </n-card>
    </div>
</template>

<style lang="scss" scoped>
.paper-title {
    .stu-info {
        display: flex;
        align-items: center;

        .stu-info-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 10px;
        }
    }
}

.ntable {
    margin: 10px;

    thead {
        background-color: #999;

        th {
            width: 100px;
            height: 50px;
            line-height: 50px;
            border: 2px solid black;
        }
    }

    tr {
        td {
            width: 100px;
            height: 50px;
            border: 2px solid black;
        }
    }
}

.paper-purpose {
    li {
        margin-top: 10px;
    }

}

.form1 {
    .form-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 10px;

        .input-group {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;

            .input {
                width: 100%;
            }
        }
    }
}
.f2 {
        display: inline-block;
        width: 100px;
        margin-right: 10px;
}
table {
    margin: 10px;

    tr {
        td {
            text-align: center;
            padding: 10px;

            input {
                width: 100%;
                height: 100%;
                //border: none;
                outline: none;
                text-align: center;
                box-sizing: border-box;

                &:focus {
                    border-radius: 5px;
                    border: 1px solid #000;
                }
            }
        }
    }
}

.btn-group {
    // 右下角
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    margin: 10px;

    .n-button {
        margin-left: 10px;
    }
}</style>